package com.liwei.easyweibo.wxapi;

import com.liwei.easyweibo.R;
import com.liwei.easyweibo.util.Constant;
import com.liwei.easyweibo.util.Util;
import com.tencent.mm.sdk.openapi.BaseReq;
import com.tencent.mm.sdk.openapi.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

import android.app.Activity;
import android.os.Bundle;

public class WXEntryActivity extends Activity implements IWXAPIEventHandler{
	
	private IWXAPI api; //IWXAPI 是第三方app和微信通信的openapi的接口
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		api = WXAPIFactory.createWXAPI(this, Constant.WECHAT_APPID,false);
		
//		在WXEntryActivity中将接收到的intent及实现了IWXAPIEventHandler接口的对象传递给IWXAPI接口的handleIntent方法
		api.handleIntent(getIntent(), this);
	}
	
	@Override
	public void onReq(BaseReq arg0) {
		// TODO Auto-generated method stub
		//微信发送的请求
		
	}

	@Override
	public void onResp(BaseResp resp) {
		// TODO Auto-generated method stub
		//发送到微信的请求返回的结果
		int result = 0;
		switch(resp.errCode){
		case BaseResp.ErrCode.ERR_OK:
			result = R.string.errcode_success;
			break;
		case BaseResp.ErrCode.ERR_USER_CANCEL:
			result = R.string.errcode_cancel;
			break;
		case BaseResp.ErrCode.ERR_AUTH_DENIED:
			result = R.string.errcode_deny;
			break;
		default:
			result = R.string.errcode_unknown;
			break;
		}
		
		Util.showToast(this, result);
	}

}
